// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const env = "fz-xiaochengxu-3ggm49cn525bedba";
const db = cloud.database({env});

// 云函数入口函数
exports.main = async (event, context) => {
    //获取数据库命令对象
    const _ = db.command;
    return await db.collection("encounters")
      .where({
        location: _.geoNear({
          geometry: db.Geo.Point(event.location.longitude, event.location.latitude),
          minDistance: 0,
          maxDistance: event.maxDistance
        }),
        tag: _.eq(event.encounterTag),
        date: _.gte(db.serverDate({ offset:-60 * 60 * 1000 * 24 * 3}))
      })
      .get();
}